<?php
/**
 * Created by PhpStorm.
 * User: kaycn
 * Date: 18-9-13
 * Time: 下午3:06
 */
require_once('vendor/autoload.php');

header("Content-Type: text/html; charset=UTF-8");

$test = (new \Pay\Jpay())->sendcontent();

$http = new \swoole_http_server("127.0.0.1", 9501);

$http->on("start", function ($server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});


$http->on("request", function ($request, $response) {

    $response->header("Content-Type", "json/plain");

    global $test;

        if(!array_key_exists('i',$request->get)){


           $js = \Pay\Js::getJs($test->driver);

           $js = $js->getcount_all($request->get['time']);

           $json = new \Pay\log($js);

           $check = new \Pay\check($json::$data,$request->post);

           if($check->checknew()){

               if($check->finnaly_check()){
                   $response->end('{"status":"付款成功"}');
               }else{
                   $response->end('{"status":"你没有付款成功或者如已付款请联系管理员"}');

               }

           }else{

               $response->end($json->json);

           }

           $json->save();




        }
        else {

            $data = $test->getcount($request->get['i'], $request->get['time']);

            $json = new \Pay\log($data);



            $json ->save();

            $response->end($json->json);

        }




});

$http->start();